package actions;

import java.util.List;
import java.util.Map;

import modelo.Tesina;
import modelo.Votacion;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.SessionAware;

import DAO.FactoryDAO;
import DAO.TesinaDAO;
import DAO.VotacionDAO;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Action(value = "/ResetiarVotacion")
@Result(location = "/jsp/principal/backend.jsp", name = "SUCCESS")
public class ResetiarVotacionAction extends ActionSupport implements
		SessionAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Map<String, Object> session;

	public String execute() {

		TesinaDAO tDAO = FactoryDAO.getTesinaDAO();
		List<Tesina> tesinas = tDAO.obtenerTodasLasTesis();
		for (Tesina t : tesinas) {
			t.setVotoNegativos("0");
			t.setVotoPositivos("0");
			tDAO.modificarTesina(t);
		}
		VotacionDAO vDAO = FactoryDAO.getVotacionDAO();
		List<Votacion> votaciones = vDAO.obtenerTodasLasVotaciones();
		for (Votacion v : votaciones) {
				vDAO.eliminar(v);
		}
		session=ActionContext.getContext().getSession();
		session.put("contenido", "/jsp/contenidoBack/gridVotacion.jsp");
		return "SUCCESS";
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub

	}

}
